home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Online / News / Thor / HD-Install / thor.lha / rexx / BBSRead / AddAmiNetFileList.br next >
Text File  |  1997-05-19  |  5KB  |  196 lines

  1. /*
  2.  * $VER: AddAmiNetFileList.br 3.4 (16.5.97)
  3.  *
  4.  * Arexx script to add a AmiNet RECENT/INDEX list to the database.
  5.  *
  6.  * Based on AddAmiNetFileList.br v3.1 provided by the THOR team.
  7.  *
  8.  * Modified by Henrik Dissing to handle dates and file sizes correctly.
  9.  *
  10.  * V3.4 changes done by Eirik Synnes
  11.  *
  12.  *
  13.  * V3.3:    Now also strips '*' from date field to prevent "Aritmethic
  14.  *            conversion error" when loading INDEX files from sites
  15.  *            not holdning the full database.
  16.  *            Now, hopefully, detects lists in "illegal" formats
  17.  *
  18.  * V3.4: The ouput has been made simpler in order to increase overall speed
  19.  *       Added QUIET switch for no output (about 10% faster)
  20.  *       Made some of the error messages a bit more verbose
  21.  *       
  22.  */
  23.  
  24.     options results
  25.     /* trace results */
  26.  
  27.     parse arg argument
  28.  
  29.     template = 'BBSNAME/A,FILENAME/A,QUIET/S'
  30.  
  31.     if argument = '' | argument = '?' then
  32.     do
  33.         say '$VER: AddAminetFileList.br'  || subword(sourceline(2), 4)
  34.         say 'Template: 'template
  35.       say 'Example:  AddAminetFileList.br "Internet" "Work:Files/INDEX" QUIET'
  36.         exit
  37.     end
  38.  
  39.     if ~show('p', 'BBSREAD') then do
  40.         address command
  41.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  42.         "WaitForPort BBSREAD"
  43.     end
  44.  
  45.     address BBSREAD
  46.  
  47.     READARGS template ARGS CMDLINE argument
  48.     if rc ~= 0 then 
  49.     do
  50.         say BBSREAD.LASTERROR
  51.         say 'Template: 'template
  52.       say 'Example:  AddAminetFileList.br "Internet" "Work:Files/INDEX" QUIET'
  53.         exit
  54.     end
  55.  
  56.     if ~open(fh,ARGS.FILENAME,'Read') then 
  57.     do
  58.         say 'Unable to open file: ' || args.FILENAME
  59.         exit
  60.     end
  61.  
  62.     if ~(args.QUIET) then indexlength = seek(fh, 0, 'E'); call seek(fh, 0, 'B')
  63.  
  64.     rc = 0
  65.     signal on ERROR
  66.     signal on BREAK_C
  67.     signal on HALT
  68.  
  69.     'BUFMODE COPYBACK'        /* Enable copyback buffer mode */
  70.  
  71.     aline = readln(fh)
  72.     ltype = word(aline, 2) 
  73.     ldate = word(aline, words(aline))
  74.  
  75.     parse var ldate day '-' month '-' year
  76.     day = right(day, 2, '0')
  77.     select
  78.         when month == 'Jan' then month = '01'
  79.         when month == 'Feb' then month = '02'
  80.         when month == 'Mar' then month = '03'
  81.         when month == 'Apr' then month = '04'
  82.         when month == 'May' then month = '05'
  83.         when month == 'Jun' then month = '06'
  84.         when month == 'Jul' then month = '07'
  85.         when month == 'Aug' then month = '08'
  86.         when month == 'Sep' then month = '09'
  87.         when month == 'Oct' then month = '10'
  88.         when month == 'Nov' then month = '11'
  89.         when month == 'Dec' then month = '12'
  90.         otherwise
  91.             say "Unexpected month identifier in header:" month
  92.             call HALT
  93.     end
  94.     year = right(year, 2, '0')
  95.     if year < 95 then
  96.         year = '20'year
  97.     else
  98.         year = '19'year
  99.     ldate = date('i', year || month || day, 's') * 86400
  100.  
  101.     do until eof(fh)
  102.         aline = readln(fh)
  103.  
  104.         do while left(aline, 1) == '|'
  105.             aline = readln(fh)
  106.  
  107.             if left(aline, 5) == '|File' then
  108.             do
  109.                 legalhead = '|File              Dir        Size Age Description'
  110.                 if left(aline, length(legalhead)) ~== legalhead then
  111.                 do
  112.                     say "Unexpected list format in " || ARGS.FILENAME
  113.                     say "List header must look exactly like this:"
  114.                     say legalhead
  115.                     call HALT
  116.                 end
  117.             end
  118.         end
  119.  
  120.         if aline == "" then iterate
  121.  
  122.         if ltype == "Complete" then
  123.         do
  124.             parse var aline 1 fname 20 farea 31 fsize 36 fage 40 fdesc
  125.             fname = strip(fname)
  126.             farea = strip(farea)
  127.             fsize = strip(fsize)
  128.             fdate = ldate - (strip(fage, 'B', ' +*') * 7 * 86400)
  129.             fdesc = strip(fdesc)
  130.         end
  131.         else if ltype == "Recent" then
  132.         do
  133.             parse var aline 1 fname 20 farea 31 fsize 36 fdesc
  134.             fname = strip(fname)
  135.             farea = strip(farea)
  136.             fsize = strip(fsize, 'B', ' +')
  137.             fdate = ldate
  138.             fdesc = strip(fdesc)
  139.         end
  140.         else
  141.         do
  142.             say "Unexpected format of first line in" ARGS.FILENAME
  143.             call HALT
  144.         end
  145.  
  146.         if right(fsize, 1) == 'M' then mega = 1
  147.         else mega = 0
  148.         fsize = compress(fsize, 'KM')
  149.  
  150.         if ~datatype(fsize,'N') then fsize = 0
  151.  
  152.         if mega == 1 then
  153.             fsize = trunc(fsize * 1024.0)
  154.         fsize = fsize * 1024
  155.  
  156.         'CONFIGFAREA "' || ARGS.BBSNAME || '"' farea 
  157.  
  158.         if fdesc ~= '' then
  159.         do
  160.             drop BRFILE.
  161.  
  162.             BRFILE.NAME = fname
  163.             BRFILE.SIZE = fsize
  164.             BRFILE.DATE = fdate
  165.  
  166.             BRFILE.DESCRIPTION.COUNT = 1
  167.             BRFILE.DESCRIPTION.1 = fdesc
  168.  
  169.             'WRITEBRFILE "' || ARGS.BBSNAME || '"' farea stem BRFILE 
  170.  
  171.             if ~(args.QUIET) then do
  172.                 curperc = (seek(fh, 0) / indexlength) * 100
  173.                 if curperc ~= 100 then curperc = left(curperc, index(curperc, '.') - 1)
  174.  
  175.                 if (curperc ~= lastperc) | (farea ~= lastarea) then do
  176.                     say '1B'x'[1A' || '1B'x'[K' || '(' || curperc || '% done) Adding files from: 'farea
  177.                     lastperc = curperc; lastarea = farea
  178.                 end
  179.             end
  180.         end
  181.  
  182.     end
  183.  
  184. ERROR:
  185. HALT:
  186. BREAK_C:
  187.  
  188.     if(rc ~= 0) then 
  189.     do
  190.         say 'Error' rc 'in line' SIGL ':' BBSREAD.LASTERROR
  191.     end
  192.  
  193.     'BUFMODE ENDCOPYBACK'        /* Disable copyback buffer mode */
  194.  
  195.     exit
  196.